package com.douma._2022;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * 抖码算法，让算法学习变的简单有趣
 *
 * @作者 : 老汤
 */
public class 日志排序 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();

        String[] dateStrs = new String[n];
        for (int i = 0; i < n; i++) {
            dateStrs[i] = sc.nextLine();
        }

        Arrays.sort(dateStrs, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                // 按照时间升序排列
                return (int) (getMillisecond(o1) - getMillisecond(o2));
            }
        });

        for (String str : dateStrs) {
            System.out.println(str);
        }

        sc.close();
    }

    // 将字符串时间转化为对应的毫秒数
    private static long getMillisecond(String time) {
        int dotIndex = time.indexOf(".");
        long ms = Integer.valueOf(time.substring(dotIndex + 1));
        String[] h_m_s = time.substring(0, dotIndex).split(":");
        ms += Integer.valueOf(h_m_s[2]) * 1000;
        ms += Integer.valueOf(h_m_s[1]) * 60 * 1000;
        ms += Integer.valueOf(h_m_s[1]) * 60 * 60 * 1000;
        return ms;
    }
}
